#pragma once

#include <vtkImageData.h>
#include <vtkSmartPointer.h>

#include <cv.h>
#include <opencv2/gpu/gpu.hpp>

#include <string>
#include <vector>
#include <time.h>
#include "dirent.h"
#include <Windows.h>
#include <iostream>

class vtkOpenCVBridge
{
private:
	vtkSmartPointer<vtkImageData> m_imageData;
	std::vector<cv::Mat> m_vectorCVMat;
	std::vector<cv::gpu::GpuMat> m_vectorGPUMat;
	int m_dimensions[3];
	void vector_cvMatTogpuMat ();
	void vector_gpuMatToCvMat ();

public:
	vtkOpenCVBridge (vtkSmartPointer<vtkImageData> vtkImage, std::vector<cv::Mat> vector_cvMat, int dims[3])
	{
		m_imageData = vtkImage;
		m_vectorCVMat = vector_cvMat;
		*m_dimensions = *dims;
	}
	vtkOpenCVBridge (vtkSmartPointer<vtkImageData> vtkImage)
	{
		m_imageData = vtkImage;
		m_imageData->GetDimensions(m_dimensions);
	}
	vtkOpenCVBridge (std::vector<cv::Mat> vector_cvMat)
	{
		m_vectorCVMat = vector_cvMat;
		m_dimensions[1] = m_vectorCVMat[0].rows;
		m_dimensions[0] = m_vectorCVMat[0].cols;
		m_dimensions[2] = (int)m_vectorCVMat.size();
	}
	vtkOpenCVBridge (std::vector<cv::gpu::GpuMat> vector_gpuMat)
	{
		m_vectorGPUMat = vector_gpuMat;
		vtkOpenCVBridge::vector_gpuMatToCvMat();
		m_dimensions[0] = m_vectorCVMat[0].rows;
		m_dimensions[1] = m_vectorCVMat[0].cols;
		m_dimensions[2] = (int)m_vectorCVMat.size();
	}

	vtkSmartPointer<vtkImageData> OpenCVtoVTK ();
	std::vector<cv::gpu::GpuMat> VTKtoOpenCV_gpu ();
	std::vector<cv::Mat> VTKtoOpenCV_mat ();

	~vtkOpenCVBridge()
	{
		delete [] m_dimensions;
		m_vectorCVMat.clear();
		m_vectorGPUMat.clear();
		m_imageData->Delete();
	}
};